// pages/index/schoolSubjectResult/schoolSubjectResult.js
import Toast from '../../../miniprogram_npm/@vant/weapp/toast/toast';

import {
    GetMajorBySchool, 
} from '../../../api/index'


Page({

  /**
   * 页面的初始数据
   */
  data: {
    listArray:[],
    yearshow:false,
        yearArray:[{
            name: '2024年',
        }],
        pageNo:1,
                    totalPages:0,
                    nomore:false,
                    model:null,
                    queryType:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
      console.log(options)
      console.log(JSON.parse(options.item))
      this.setData({
        model:JSON.parse(options.item),
        queryType:options.queryType
      })
    this._GetMajorBySchool('?queryType=' + this.data.queryType + "&pageNum=" + this.data.pageNo + '&pageSize=20' + "&schoolId=" + this.data.model.schoolId, true)
  },

  screenItemYearAction(){
    this.setData({
        yearshow:true
    })
},

onClose() {
    this.setData({ yearshow:false });
  },

  onSelect(event) {
    console.log(event.detail);
    this.onClose()
    if (event.detail == '2024年') {
        return
    }
  },

  
_GetMajorBySchool(data,isLoading) {
    console.log(data)
    console.log(this.data.listArray)
    let that = this
    if (this.data.totalPages <= this.data.listArray.length && this.data.totalPages != 0) {
        console.log('对吗')
        this.setData({
          nomore: true,
          changePage:true
        })
        return;
      }
    
      GetMajorBySchool(data, isLoading).then(res => {
        console.log(res)
        let code = res.code;
        // Toast('成功')
        if (code == 200) {
            let array = res.rows;
            setTimeout(function() {
                //要实现延迟执行效果的代码快
                that.setData({
                    listArray: that.data.listArray.concat(array),
                    pageNo: that.data.pageNo + 1,
                    totalPages: res.total,
                  });
                }, 100);//设置延迟效果的具体时间
 
              if (that.data.totalPages <= that.data.listArray.length && that.data.totalPages != 0) {
                    that.setData({
                        nomore: true
                    })
              } 
        } else {
            Toast(res.msg)
        }
    })
},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    console.log('下拉刷新')
    // 显示顶部刷新图标
    wx.showNavigationBarLoading();
    this.setData({
        listArray:[],
        pageNo: 1,
        totalPages: 0,
        nomore: false,
      })
      this._GetMajorBySchool('?queryType=' + this.data.queryType + "&pageNum=" + this.data.pageNo + '&pageSize=20' + "&schoolId=" + this.data.model.schoolId, false)
    // 隐藏导航栏加载框
    wx.hideNavigationBarLoading();
    // 停止下拉动作
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    console.log('上拉加载更多')
    this._GetMajorBySchool('?queryType=' + this.data.queryType + "&pageNum=" + this.data.pageNo + '&pageSize=20' + "&schoolId=" + this.data.model.schoolId, false)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})